﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GeoFly
{
    public partial class MidGridOutDialog : Form
    {
        public MidGridOutDialog()
        {
            InitializeComponent();
        }
        public void SetData()
        {
            HydroSimulate.g_GridResultOut.iPcp = this.checkedListBox1.CheckedIndices.Contains(0);
            HydroSimulate.g_GridResultOut.iTempMax = this.checkedListBox1.CheckedIndices.Contains(1);
            HydroSimulate.g_GridResultOut.iTempMin = this.checkedListBox1.CheckedIndices.Contains(2);
            HydroSimulate.g_GridResultOut.iTempMean = this.checkedListBox1.CheckedIndices.Contains(3);
            HydroSimulate.g_GridResultOut.iSlr = this.checkedListBox1.CheckedIndices.Contains(4);
            HydroSimulate.g_GridResultOut.iHmd = this.checkedListBox1.CheckedIndices.Contains(5);
            HydroSimulate.g_GridResultOut.iWnd = this.checkedListBox1.CheckedIndices.Contains(6);
            HydroSimulate.g_GridResultOut.iPET = this.checkedListBox1.CheckedIndices.Contains(7);
            HydroSimulate.g_GridResultOut.iAET = this.checkedListBox1.CheckedIndices.Contains(8);
            HydroSimulate.g_GridResultOut.iCI = this.checkedListBox1.CheckedIndices.Contains(9);
            HydroSimulate.g_GridResultOut.iSnowWater = this.checkedListBox1.CheckedIndices.Contains(10);
            HydroSimulate.g_GridResultOut.iAI = this.checkedListBox1.CheckedIndices.Contains(11);
            HydroSimulate.g_GridResultOut.iRouteOut = this.checkedListBox1.CheckedIndices.Contains(12);
            HydroSimulate.g_GridResultOut.iSurfQ = this.checkedListBox1.CheckedIndices.Contains(13);
            HydroSimulate.g_GridResultOut.iLatQ = this.checkedListBox1.CheckedIndices.Contains(14);
            HydroSimulate.g_GridResultOut.iBaseQ = this.checkedListBox1.CheckedIndices.Contains(15);
            HydroSimulate.g_GridResultOut.iInfilRate = this.checkedListBox1.CheckedIndices.Contains(16);
            HydroSimulate.g_GridResultOut.iWaterYieldType = this.checkedListBox1.CheckedIndices.Contains(17);
            HydroSimulate.g_GridResultOut.iProfileSoilWater = this.checkedListBox1.CheckedIndices.Contains(18);
            HydroSimulate.g_GridResultOut.iAvgSoilWater = this.checkedListBox1.CheckedIndices.Contains(19);

            HydroSimulate.g_GridResultOut.OutputStartDate = (DateTime)this.comboBox_StartDate.SelectedItem;
            HydroSimulate.g_GridResultOut.OutputEndDate = (DateTime)this.comboBox_EndDate.SelectedItem;
            HydroSimulate.g_GridResultOut.OutputPath = TextBox_OutputPath.Text;
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确信要覆盖掉原来的设置吗？", "警告", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                SetData();
                HydroSimulate.g_GridResultOut.WriteMidOutFile(HydroSimulate.path + "\\SysPara\\MidGridOut.txt");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog dialog = new FolderBrowserDialog();
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                this.TextBox_OutputPath.Text = dialog.SelectedPath;
            }
        }

        private void MidGridOutDialog_Load(object sender, EventArgs e)
        {
            DateTime startDate = HydroSimulate.g_ClimatePara.StartDate;
            DateTime endDate = HydroSimulate.g_ClimatePara.EndDate;
            TimeSpan span = new TimeSpan(1, 0, 0, 0);
            for (DateTime date = startDate; date <= endDate; date += span)
            {
                this.comboBox_StartDate.Items.Add(date);
                this.comboBox_EndDate.Items.Add(date);
            }
            int count = this.comboBox_EndDate.Items.Count;
            this.comboBox_StartDate.SelectedIndex = 0;
            this.comboBox_EndDate.SelectedIndex = count - 1;
            this.TextBox_OutputPath.Text = HydroSimulate.g_GridResultOut.OutputPath;

            this.checkedListBox1.SetItemChecked(0, HydroSimulate.g_GridResultOut.iPcp);
            this.checkedListBox1.SetItemChecked(1, HydroSimulate.g_GridResultOut.iTempMax);
            this.checkedListBox1.SetItemChecked(2, HydroSimulate.g_GridResultOut.iTempMin);
            this.checkedListBox1.SetItemChecked(3, HydroSimulate.g_GridResultOut.iTempMean);
            this.checkedListBox1.SetItemChecked(4, HydroSimulate.g_GridResultOut.iSlr);
            this.checkedListBox1.SetItemChecked(5, HydroSimulate.g_GridResultOut.iHmd);
            this.checkedListBox1.SetItemChecked(6, HydroSimulate.g_GridResultOut.iWnd);
            this.checkedListBox1.SetItemChecked(7, HydroSimulate.g_GridResultOut.iPET);
            this.checkedListBox1.SetItemChecked(8, HydroSimulate.g_GridResultOut.iAET);
            this.checkedListBox1.SetItemChecked(9, HydroSimulate.g_GridResultOut.iCI);
            this.checkedListBox1.SetItemChecked(10, HydroSimulate.g_GridResultOut.iSnowWater);
            this.checkedListBox1.SetItemChecked(11, HydroSimulate.g_GridResultOut.iAI);
            this.checkedListBox1.SetItemChecked(12, HydroSimulate.g_GridResultOut.iRouteOut);
            this.checkedListBox1.SetItemChecked(13, HydroSimulate.g_GridResultOut.iSurfQ);
            this.checkedListBox1.SetItemChecked(14, HydroSimulate.g_GridResultOut.iLatQ);
            this.checkedListBox1.SetItemChecked(15, HydroSimulate.g_GridResultOut.iBaseQ);
            this.checkedListBox1.SetItemChecked(16, HydroSimulate.g_GridResultOut.iInfilRate);
            this.checkedListBox1.SetItemChecked(17, HydroSimulate.g_GridResultOut.iWaterYieldType);
            this.checkedListBox1.SetItemChecked(18, HydroSimulate.g_GridResultOut.iProfileSoilWater);
            this.checkedListBox1.SetItemChecked(19, HydroSimulate.g_GridResultOut.iAvgSoilWater);
        }
    }
}